﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZeroBug.EasyFlow.Core
{
    public class Recipe
    {
        private FlowManager _flowManager;

        /// <summary>
        /// 点位参数
        /// </summary>
        public SerializableDictionary<string, Variable> Variables { get; set; }
        public SerializableDictionary<string, Tray> Trays { get; set; }
        public Recipe()
        {
            this.Variables = new SerializableDictionary<string, Variable>();
            this.Trays = new SerializableDictionary<string, Tray>();
        }
        public Recipe(FlowManager flowManager)
            : this()
        {
            this._flowManager = flowManager;
        }
        public void AddVariable(Variable variable)
        {
            if (Variables.ContainsKey(variable.Name))
                Variables[variable.Name] = variable;
            else
                Variables.Add(variable.Name, variable);

            _flowManager.VariableManager.AddVariable(variable, VariableFrom.Recipe);
        }

        public void SetFlowManager(FlowManager flowManager)
        {
            this._flowManager = flowManager;
        }

        internal void LoadOriginalValue()
        {
            foreach (var variable in Variables.Values)
            {
                variable.LoadFromOriginalValue();
            }
        }
    }
}
